﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Vision.Core.ActivityComponents.Assembly
{
    // Interaction logic for AssemblyServiceContextDesigner.xaml
    public partial class AssemblyServiceContextDesigner
    {
        //private string _fileName = "";

        public AssemblyServiceContextDesigner()
        {
            InitializeComponent();

            //this.Loaded += new RoutedEventHandler(AssemblyServiceContextDesigner_Loaded);
            //this.Unloaded += new RoutedEventHandler(AssemblyServiceContextDesigner_Unloaded);
        }

        /*
        void AssemblyServiceContextDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            this.ModelItem.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ModelItem_PropertyChanged);

            if (!this.Context.Services.Contains<Services.IAssemblyListService>())
                this.Context.Services.Publish<Services.IAssemblyListService>(new Services.AssemblyListService());
        }

        void AssemblyServiceContextDesigner_Unloaded(object sender, RoutedEventArgs e)
        {
            this.ModelItem.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(ModelItem_PropertyChanged);
        }

        void ModelItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "AssemblyFileName")
            {
                Services.IAssemblyListService assemblyListService = this.Context.Services.GetService<Services.IAssemblyListService>();

                if (_fileName != string.Empty)
                    assemblyListService.RemoveAssembly(_fileName);

                if (this.ModelItem.Properties["AssemblyFileName"].ComputedValue != null)
                {
                    //_fileName = this.ModelItem.Properties["AssemblyFileName"].ComputedValue.ToString();
                    _fileName = (this.ModelItem.Properties["AssemblyFileName"].Value.Content.ComputedValue as Microsoft.VisualBasic.Activities.VisualBasicValue<String>).ExpressionText.Trim('"');
                    assemblyListService.AddAssembly(_fileName);
                }
                else
                    _fileName = "";
            }
        }
        */
    }
}
